package cn.blunce.viewexercises.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import cn.blunce.viewexercises.R;

public class MainActivity extends Activity {

    private ListView mListView;
    private ArrayAdapter<String> mAdapter;

    private String[] items;

    private Intent[] intents;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initPara();
        initView();
    }

    private void initPara() {
        items = new String[]{
                "TextView重写",
                "item_2",
                "item_3",
                "item_4"
        };
        mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items);
        intents = new Intent[]{
                new Intent(MainActivity.this, Item1Activity.class),
                new Intent(MainActivity.this, Item2Activity.class),
                new Intent(MainActivity.this, Item3Activity.class),
                new Intent(MainActivity.this, Item4Activity.class)
        };
    }

    private void initView() {
        mListView = (ListView) findViewById(R.id.lv_views);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                startActivity(intents[i]);
            }
        });
    }
}
